package com.zc.im.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/7/11.
 */
public class DateUtils {
    private static Logger log = LoggerFactory.getLogger(DateUtils.class);

    public static Date strFormatDateYmdHms(String dateStr){
        Date date = new Date();
        try{
            if(StringUtils.isEmpty(dateStr)){
                return date;
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            date = dateFormat.parse(dateStr);
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return date;
    }

    public static Date strFormatDateYmd(String dateStr){
        Date date = new Date();
        try{
            if(StringUtils.isEmpty(dateStr)){
                return date;
            }
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            date = dateFormat.parse(dateStr);
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return date;
    }


    public static String dateFormatStrYmdHms(Date date){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String timeStr = null;
        if(date == null){
            return dateFormat.format(new Date());
        }
        timeStr = dateFormat.format(date);
        return timeStr;
    }
}
